<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}
</style>
<link rel="stylesheet" href="${ctx}/ace/css/just-tip.css" />
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">
		<div class="page-header"
			style="margin-bottom: 0px; padding-bottom: 10px;">
			<h1 id="fu_name"></h1>
		</div>
		<form id="queryForm" method="post">
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
						<div class="widget-box"
							style="border: 0px solid #ccc; border-top: none; border-bottom: none;">
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">每周大奖参与汇总统计</h4>
								<div class="widget-toolbar">
									<a href="#" data-action="collapse"> <i
										class="ace-icon fa fa-chevron-up"></i>
									</a>
								</div>
							</div>
							<div class=" widget-body">
								<div class="widget-main">
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" style="text-align: right"
											for="sex">日期:</label>
										<div class="col-sm-8" style="padding-left: 0px">
										    <div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="startTime" name="startTime"> 
												 <span class="input-group-addon" style="width: 6px"> 
												    <i class="fa fa-exchange"></i>
												 </span>
												 <input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="endTime" name="endTime">
											 </div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="col-md-12 center">
					<div class="clearfix form-actions">
						<button class="btn btn-purple  no-border" type="button"
							name="btn-query" onclick="query_any()" id="btn-query">
							<i class="ace-icon fa fa-search icon-on-right bigger-110"></i> 查询
						</button>
						&nbsp;&nbsp;&nbsp;
						<button class="btn btn-grey  no-border" type="reset">
							<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i> 重置
						</button>
					</div>
				</div>
			</div>
		</form>
		<div class="row">
			<div class="col-xs-12">
				<table id="jquery-table"
					class="table table-striped table-bordered table-hover">
				</table>
			</div>
		</div>
	</div>
	<%@ include file="/common/common-js.jsp"%>
	<script type="text/javascript" src="${ctx}/js/common-loading.js"></script>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script type="text/javascript" src="${ctx}/ace/js/jquery.dataTables.min.js"></script>
	<script src="${ctx}/ace/js/justTools.js"></script>
	<script type="text/javascript">
	    
	    var souceList = null;
		var jqTable = null;
		
		$(document).ready(function() {
			//时间范围插件初始化
			$('.date-picker').datepicker({
				autoclose : true,
				format : 'yyyy-mm-dd'
			});
		});
		
		//【查询】按钮Click事件
		function query_any() {
			if (jqTable != null) {
				jqTable.fnDraw();
			} else {
				loaddata();
			}
		}
		var loaddata = function() {
			jQuery(function($) {
				jqTable = $('#jquery-table').dataTable(
				{
					//数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
					"columnDefs" : [{
						"title" : "期号",
						"name" : "id",
						"data" : "id",
						"targets" : [ 0 ],
						"bSortable" : true,
					}, 
					{
						"title" : "开奖日期",
						"name" : "end_date",
						"data" : "end_date",
						"targets" : [ 1 ],
						"bSortable" : false,
					}, 
					{
						"title" : "活动开始时间",
						"name" : "begin_date",
						"data" : "begin_date",
						"targets" : [ 2 ],
						"bSortable" : true,
					},
					{
						"title" : "活动结束时间",
						"name" : "end_date",
						"data" : "end_date",
						"targets" : [ 3 ],
						"bSortable" : true,
					},
					{
						"title" : "奖品名称",
						"name" : "name",
						"data" : "name",
						"targets" : [ 4 ],
						"bSortable" : false,
					},
					{
						"title" : "是否已开奖",
						"name" : "lottery_status",
						"data" : "lottery_status",
						"targets" : [ 5 ],
						"bSortable" : false,
						"render": function(value, type, row) {
	                   		 if(value == 0) {
								return "未开奖";
							 } else if(value == 1) {
								return "已开奖";
							 } else {
								return "--";
							 }	 
						 },
					},
					{
						"title" : "每人次需积分",
						"name" : "cost_point",
						"data" : "cost_point",
						"targets" : [ 6 ],
						"bSortable" : false,
					}, 
					{
						"title" : "总参与人次",
						"name" : "join_num",
						"data" : "join_num",
						"targets" : [ 7 ],
						"bSortable" : false,
					}, 
					{
						"title" : "总参与人数",
						"name" : "user_num",
						"data" : "user_num",
						"targets" : [ 8 ],
						"bSortable" : false,
					}, 
					{
						"title" : "总消耗积分",
						"name" : "user_num",
						"data" : "user_num",
						"targets" : [ 9 ],
						"bSortable" : false,
						"render": function(value, type, row) {
	                   		 if(row.join_num != null && row.cost_point != null){
								return row.join_num * row.cost_point;
							 }else{
								return "--";
							 }				 
						 },
					}, 
					{
						"title" : "详情UV",
						"name" : "detail_uv",
						"data" : "detail_uv",
						"targets" : [ 10 ],
						"bSortable" : false,
					},
					{
						"title" : "详情PV",
						"name" : "detail_pv",
						"data" : "detail_pv",
						"targets" : [ 11 ],
						"bSortable" : false,
					},
					{
						"title" : "提交UV",
						"name" : "submit_uv",
						"data" : "submit_uv",
						"targets" : [ 12 ],
						"bSortable" : false,
					},
					{
						"title" : "提交PV",
						"name" : "submit_pv",
						"data" : "submit_pv",
						"targets" : [ 13 ],
						"bSortable" : false,
					},
					{
						"title" : "参与转化率", // 提交UV/详情UV
						"name" : "submit_uv",
						"data" : "submit_uv",
						"targets" : [ 14 ],
						"bSortable" : false,
						"render": function(value, type, row) {
	                   		 if(row.submit_uv != null && row.detail_uv != null){
								return row.submit_uv / row.detail_uv;
							 }else{
								return "--";
							 }				 
						 },
					}],
					"sAjaxSource" : ctx + "/stat_weekly_award/queryWeeklyAwardStatistics.action",//数据源URL
					"fnServerData" : function(sSource, aoData,fnCallback) {   //从服务器请求数据
						var data = $('#queryForm').serializeObject();
						data.aoData = JSON.stringify(aoData);
						$.ajax({
							"type" : "POST",
							"dataType" : 'json',
							"url" : sSource,
							"data" : data,
							beforeSend : function() {
								$(".load_bg").removeAttr("style");
								$(".load_img").removeAttr("style");
							},
							"success" : function(resp) {
								$(".load_bg").attr("style","display:none");
								$(".load_img").attr("style","display:none");
								$("#hidden_pass").attr("style","display:block");
								$('#jquery-table').removeClass("dataTable");
								fnCallback(resp);
								initListPage();
							},
							"error" : function(XMLHttpRequest,
									textStatus, errorThrown) {
								$(".load_bg").attr("style","display:none");
								$(".load_img").attr("style","display:none");
								alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
							}
						});
					},
					"fnRowCallback" : function(nRow, aData,
							iDisplayIndex, iDisplayIndexFull) {
						nRow.ondblclick = function() {
						}
					},
					"bDestroy" : true,
					"bScrollInfinite" : true,
					"sScrollXInner" : "100%",
					"sScrollY" : "100%",//如果不设置，IE会有问题
					"aaSorting" : [ [ 0, "desc" ] ]
				//初始化加载，默认按第几列排序、排序方式（列从0开始计算)
				});
			});
		}

		//时间控件
		jQuery(function($) {
			$(".date-picker").datepicker({
				autoclose : true
			}).next().on(ace.click_event, function() {
				$(this).prev().focus();
			});
		});
	</script>
</body>
</html>